<?php
ptaste();
class JEng3dPartyObject
{
  public $aparty=null;
  function __construct($party)
  {
    $this->aparty=$party;
  }
  function party()
  {
    return $this->aparty;
  }
}

class PartyCaptcha extends JEng3dPartyObject
{
	function __construct($party)
	{
	  parent::__construct($party);
	}
	function render()
	{
		unset($_SESSION['kcaptcha_tries']);
		require_once($this->party()->site()->conf()->get("party_path")."/kcaptcha.php");
		$captcha=new KCAPTCHA();
		//$_SESSION['kcaptcha_key']=KCAPTCHA::makeKCAPTCHA();//$captcha()->getKeyString();
		//$captcha->makeKCAPTCHA();
	}
	function verify($code)
	{
		if (!isset($_SESSION['kcaptcha_key']))
		 return false;
		if (empty($_SESSION['kcaptcha_key']))
		  return false;
		$res=false;
		if ($_SESSION['kcaptcha_key']==$code)
			$res=true;
		else
			$res=false;
		unset($_SESSION['kcaptcha_key']);
		return $res;
	}
	function test($code)
	{
		if (!isset($_SESSION['kcaptcha_key']))
		 return 1;
		if (empty($_SESSION['kcaptcha_key']))
		 return 1;
		if ($_SESSION['kcaptcha_key']==$code)
			$res=0;
		else
			$res=1;
		if (!isset($_SESSION['kcaptcha_tries']))
			$_SESSION['kcaptcha_tries']=0;
		$trs=$_SESSION['kcaptcha_tries'];
		$trs++;
		$_SESSION['kcaptcha_tries']=$trs;
		if ($res && $trs>10)
		{
			unset($_SESSION['kcaptcha_key']);
			unset($_SESSION['kcaptcha_tries']);
			$res=2;
		}
		return $res;
	}
}


class JEng3dParty extends SiteObject
{
  public $aCaptcha=null;
  function __construct($site,$logger=null)
  {
    parent::__construct($site,$logger);
  }
  
  function captcha()
  {
    if (!$this->aCaptcha) $this->aCaptcha=new PartyCaptcha($this);
	return $this->aCaptcha;
  }
}

?>